package leetcode7;

public class test30 {
    /**
     * 138. 随机链表的复制
     * @param head
     * @return
     */
    public Node copyRandomList(Node head) {
        if(head == null)return null;
        Node cur = head;
        Map<Node,Node> map = new HashMap<>();
        while(cur != null){
            map.put(cur,new Node(cur.val));
            cur = cur.next;
        }
        cur = head;
        while(cur != null){
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }
}
